1. Technical Field of the Invention
This invention pertains to source code translation. More particularly, it relates to a safe system and method for reversibly translating source code between unlike character sets.
2. Background Art
More and more often companies are using workstation tools to change or maintain mainframe software source code. However, the mainframes use the IBM EBCDIC character encoding system while workstations use the ASCII system. For the most used characters, there are safe and reversible mappings between the two encoding systems. Unfortunately, this is not true for all possible characters, because there are no equivalents in both systems, because of varying locations of characters within variations of the same system, and because some characters have special control meanings in each system.
Generally, each programming language uses a set of characters for its operational syntax. By ensuring these characters are mapped reversibly, a translated program can be made to compile on both the mainframe and the workstation. However, mainframe software source code may contain any of the 256 possible characters in program comments and program text literals. Although the usual frequency of occurrence of unsafe characters is very small, if any of those characters are translated to workstation control characters, the program may not compile or be editable or even viewable. If any of those characters are not mapped in a reversible way, they will be different when the program is returned to the mainframe. At best, this may make a comment less understandable; at worst it will change the data in a program literal with unpredictable and possibly disastrous results if not corrected.
Generally, the upload and download character translation mapping tables are synchronized as much as possible for the most used characters. This often fails because it is not always possible to use the same tool or synchronized tables for both the upload and download. It also doesn""t allow all 256 possible values to be safely translated. Usually, separate fix-up work is required to detect and correct translation errors.
Consequently, there is a need in the art for a translation system and method which eliminates the need for maintaining synchronized translation mapping tables and the need for separate fix-up work.
Another solution is to use a special escape character before an untranslated value and then convert the untranslated value to a two character value in hexadecimal format. This solution does not work with source code because it changes the length of certain records and, more importantly, it changes the length of program literals, which could make the program not compile.
Consequently, there is a need in the art for a translation system and method which does not change the length of source code records or program text literals.
It is an object of the invention to provide an improved system and method for translating source code.
It is a further object of the invention to provide a system and method for translating source code such that it is possible to move mainframe software source code to a workstation, operate on the code, and move it back to the mainframe, knowing that the character translations are safe and reversible.
It is a further object of the invention to provide a system and method for translating source code which eliminates errors due to unsafe and un-reversible translations both on the workstation and on the mainframe.
A system and method is provide for translating source code. A mapping table of syntactically necessary characters is provided for translating source characters from a first format to a second format. A marker character is used to replace other characters in the source code while translating and preserving the original, replaced source character in a comment file. Upon reverse translating, syntactically necessary characters are translated back into the first format using the mapping table, and marker characters are replaced by reverse translated original source characters from the comment file.
In accordance with a more specific embodiment of the invention, original characters replaced by the marker character are translated into a two-character hexadecimal representation, and then reverse translated from that two-character hexadecimal representation back into original source characters, in order to keep the original characters replaced by the marker character from preventing compilation or editing.
In accordance with an aspect of the invention, there is provided a computer program product configured to be operable to translate source code using a mapping table, a marker character, and a comment file of source code characters replaced by the marker character.
Other features and advantages of this invention will become apparent from the following detailed description of the presently preferred embodiment of the invention, taken in conjunction with the accompanying drawings.